<?php

/**
 * This is the model class for table "web_option".
 *
 * The followings are the available columns in table 'web_option':
 * @property integer $id
 * @property string $site_name
 * @property string $site_description
 * @property string $site_url
 * @property string $site_mail
 * @property string $site_logo
 * @property string $seo_title
 * @property string $seo_keyword
 * @property string $seo_description
 * @property string $payment_paypal
 * @property string $payment_western_union
 * @property string $order_prefix
 * @property string $service_phone
 * @property string $service_mail
 * @property string $service_livechat
 */
class WebOption extends CActiveRecord {

    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return WebOption the static model class
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'web_option';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('site_name, site_description, payment_paypal', 'required'),
            array('site_name, site_description, site_url, site_mail, site_logo, seo_title, seo_keyword, seo_description, payment_paypal, service_phone, service_mail, sns_facebook, sns_youtube, sns_twitter, sns_google', 'length', 'max' => 255),
            array('order_prefix', 'length', 'max' => 20),
            array('payment_western_union, service_livechat', 'safe'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, site_name, site_description, site_url, site_mail, site_logo, seo_title, seo_keyword, seo_description, payment_paypal, payment_western_union, order_prefix, service_phone, service_mail, service_livechat, sns_facebook, sns_youtube, sns_twitter, sns_google', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'id' => 'ID',
            'site_name' => '网站名称',
            'site_description' => '网站描述',
            'site_url' => '网站地址 (URL)',
            'site_mail' => '管理员邮箱',
            'site_logo' => '网站LOGO',
            'seo_title' => 'SEO网站标题',
            'seo_keyword' => '网站关键字',
            'seo_description' => 'SEO网站描述',
            'payment_paypal' => 'PayPal邮箱',
            'payment_western_union' => '西联汇款信息',
            'order_prefix' => '订单前缀',
            'service_phone' => '客服电话',
            'service_mail' => '客服邮箱',
            'service_livechat' => 'Livechat代码',
            'sns_facebook' => 'Facebook',
            'sns_youtube' => 'YouTube',
            'sns_twitter' => 'Twitter',
            'sns_google' => 'Google+',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id', $this->id);
        $criteria->compare('site_name', $this->site_name, true);
        $criteria->compare('site_description', $this->site_description, true);
        $criteria->compare('site_url', $this->site_url, true);
        $criteria->compare('site_mail', $this->site_mail, true);
        $criteria->compare('site_logo', $this->site_logo, true);
        $criteria->compare('seo_title', $this->seo_title, true);
        $criteria->compare('seo_keyword', $this->seo_keyword, true);
        $criteria->compare('seo_description', $this->seo_description, true);
        $criteria->compare('payment_paypal', $this->payment_paypal, true);
        $criteria->compare('payment_western_union', $this->payment_western_union, true);
        $criteria->compare('order_prefix', $this->order_prefix, true);
        $criteria->compare('service_phone', $this->service_phone, true);
        $criteria->compare('service_mail', $this->service_mail, true);
        $criteria->compare('service_livechat', $this->service_livechat, true);

        return new CActiveDataProvider($this, array(
                    'criteria' => $criteria,
                ));
    }
    
    /**
     * 订单前缀
     * @return type
     */
    public function getOrderPrefix(){
        $model = $this->find();
        return $model->order_prefix;
    }

}